package org.geekbang.thinking.in.spring.ioc.bean.lifecycle;

import com.think.in.spring.ioc.overview.domain.User;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;

/**
 *
 * 元信息配置demo :
 *      properties的方式
 * @author : zjj
 * @date : 2022/2/24 16:46
 */
public class BeanMetadataConfigurationDemo {

    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory =new DefaultListableBeanFactory();

        PropertiesBeanDefinitionReader beanDefinitionReader = new PropertiesBeanDefinitionReader(beanFactory);

        String location = "/META-INF/user.properties";
        Resource resource = new ClassPathResource(location);
        EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
        int number = beanDefinitionReader.loadBeanDefinitions(encodedResource);
        System.out.println("加载类的个数："+number);
        User user = beanFactory.getBean("user", User.class);
        System.out.println("user:" + user);

    }
}
